const enterUp = {
  methods: {
    getInput(){
      let textInp = []
      let list = document.getElementsByTagName("input")
      // console.log(list)
      let int = setInterval(() => {
        if(list.length != 0){
          clearInterval(int)
          for (const e of list) {
            // console.log(e)
            // if (e.outerHTML.indexOf('readonly') != -1) continue
            if (e.placeholder.indexOf('日期') != -1) continue
            if (e.disabled) continue
            if (e.type == 'text' || e.type == 'password') {
              textInp.push(e)
            }
          }
        }
      }, 100)
      // console.log('getInput' , textInp)
      return textInp
    },
    nextFocus(e,inpList){
      // console.log(this.inpList)
      e.target.blur()
      let index = inpList.indexOf(e.target)
      if (index != -1) {
        if (index != inpList.length - 1) {
          inpList[index].parentNode.classList.remove("is-focus")
          let regList = document.getElementsByClassName('region')
          let dropList = document.getElementsByClassName('el-select-dropdown')
          regList.forEach(x => {
            x.style.display = 'none'
          })
          dropList.forEach(x => {
            x.style.display = 'none'
          })
          let tmp = document.getElementsByClassName('el-autocomplete-suggestion')
          tmp.forEach(e => {
            // console.log(e)
            e.style.display = 'none'
          })
          inpList[index + 1].focus()  // 设置焦点  焦点跳到下一个输入框
          // let evt = document.createEvent("UIEvents")
          // evt.keyCode = 9
          // evt.initEvent("keyup", true, true)
          // this.dispatchEvent(evt)
        }
      }
    }
  },
  mounted(){
    // console.log('mounted')
    let that = this
    document.onkeyup = function(event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      // console.log(e)
      if(e && e.keyCode == 13) {
        that.nextFocus(e, that.inpList)
      }
    }
  //   let _this = this
  //   let inpList = this.inpList
    
  //   console.log(this.$el)
  //   document.onkeyup = function(event){
  //     let e = event || window.event || arguments.callee.caller.arguments[0]
  //     if(e && e.keyCode == 13){ // 按 enter
  //       _this.nextFocus(e, inpList)
  //       return
  //       console.log(_this.pageSession)
  //       console.log(inpList)
  //       // console.log(e)
  //       console.log(e.target)
  //       // console.log(e.path[0])
  //       // console.log(e.target == e.path[0])
  //       // console.log(e.target == e.path[0])
  //       // console.log(inpList[0])
  //       // console.log(inpList[0] == e.target)
  //       e.target.blur()
  //       let index = inpList.indexOf(e.target)  // 获取当前焦点输入框所处的位置 
  //       console.log(index) 
  //       if (index != -1) {
  //         // if (index == this.inpList.length - 1) {  // 判断是否是最后一个输入框
  //         //   // console.log('最后一个输入框')
  //         //   // let confirmCB = () => {_this.preservation()}
  //           // _this.$confirm('最后一个输入框已经输入，是否提交？', '', {
  //           //   confirmButtonText: '确定',
  //           //   cancelButtonText: '取消'
  //           // }).then(() => {
  //           //   _this.preservation()
  //           // })
  //         // } else {
  //         //   // console.log('不是最后一个输入框')
  //         //   this.inpList[index + 1].focus()  // 设置焦点  焦点跳到下一个输入框
  //         // }

  //         if (index != inpList.length - 1) {
  //           inpList[index].parentNode.classList.remove("is-focus")
  //           let regList = document.getElementsByClassName('region')
  //           let dropList = document.getElementsByClassName('el-select-dropdown')
  //           regList.forEach(x => {
  //             x.style.display = 'none'
  //           })
  //           dropList.forEach(x => {
  //             x.style.display = 'none'
  //           })
  //           let tmp = document.getElementsByClassName('el-autocomplete-suggestion')
  //           tmp.forEach(e => {
  //             // console.log(e)
  //             e.style.display = 'none'
  //           })
  //           inpList[index + 1].focus()  // 设置焦点  焦点跳到下一个输入框
  //           // let evt = document.createEvent("UIEvents")
  //           // evt.keyCode = 9
  //           // evt.initEvent("keyup", true, true)
  //           // this.dispatchEvent(evt)
  //         }
  //       }
  //     }
  //   }
  },
  activated(){
    // console.log('activated')
    let that = this
    document.onkeyup = function(event) {
      let e = event || window.event || arguments.callee.caller.arguments[0]
      // console.log(e)
      if(e && e.keyCode == 13) {
        that.nextFocus(e, that.inpList)
      }
    }
  }
}

export default enterUp